<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>
<?=$page_title?>
</title>
<base href="<?=base_url()?>" />
<script type="text/javascript" src="js/jquery.js"></script>
<!--time-->
<link rel="stylesheet" href="themes/base/jquery.ui.all.css">
<script src="js/ui/jquery.ui.core.js"></script>
<script src="js/ui/jquery.ui.widget.js"></script>
<script src="js/ui/jquery.ui.datepicker.js"></script>
<link rel="stylesheet" href="css/demos.css">

<link href="css/clientpublic.css" rel="stylesheet" type="text/css">
<link href="css/esui.css" rel="stylesheet" type="text/css">
<link href="css/initaccount.css" rel="stylesheet" type="text/css">
<link href="css/guo.css" rel="stylesheet" type="text/css">

<script type="text/javascript"
	src="js/fancybox/jquery.fancybox-1.3.4.pack.js"></script>
<script type="text/javascript"
	src="js/fancybox/jquery.easing-1.3.pack.js"></script>
<script type="text/javascript"
	src="js/fancybox/jquery.mousewheel-3.0.4.pack.js"></script>
<link rel="stylesheet" type="text/css"
	href="js/fancybox/jquery.fancybox-1.3.4.css" />
<link rel="stylesheet" type="text/css" href="css/jia.css" />
<!--自动搜索-->
<script language='javascript' src='js/suggest.js'></script>
<link href="js/suggest.css" rel="stylesheet" type="text/css">
<!--共享弹出框-->
<link href="styles/core.css" type="text/css" rel="stylesheet" />
<script src="scripts/popup_layer.js" type="text/javascript"
	language="javascript"></script>
<script type="text/javascript">
	$(document).ready(function() {
		jQuery.ajaxSetup ({cache:false}); /*让ajax不调用浏览的缓存*/
		$(".various1").fancybox({
		'titleShow'     : false,
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic',
		'easingIn'      : 'easeOutBack',
		'easingOut'     : 'easeInBack',
		'hideOnOverlayClick' : false,
		'onClosed'		: function(){
			 //window.location.reload();
			},
		'onComplete'	: function() {
				var suggest = new GoogleSuggest("myform", "customer_name", 0,'');
			}
		});

		$("#MainBody input.g_title_sub").click(function(){
             var name=$.trim($("#name").val());
             if(name == ""){
               alert("请输入客户名称后查询");
               $("#name").focus();
             }else{
				location.href="<?= base_url()?>index.php/customer/check/"+name+"";
             }
		})

		$("#check_info").change(function(){
			var user_id = $("#check_info").val();
			location.href="<?= base_url()?>index.php/customer/check_user_messages/"+user_id+"";
		})

		$("#county_button").click(function(){
			var city_id = $("#city").val();
			var county_id = $("#county").val();
			if(city_id == 'zero'){
				alert('请选择市局');
			}else{
				location.href="<?= base_url()?>index.php/customer/city_customers/"+city_id+"/"+county_id+"";
			}
		})
	});
</script>
</head>
<body>
	<div id="Holder">
		<div id="MainPage">
			<!---------头部------------->
			<?php include('top.php')?>
			<div id="Subnav">
				<ul>
					<li class="active show"></li>
				</ul>
			</div>
			<!---------中间部分------------->
			<div id="MainBody">
				<div class="g_title">
					<div class="g_earch">
						<input type="text" class="g_title_text" value="客户名称"
							onClick="this.value=''" id="name">
						<!-- <select name="top_level" id="top_level">
							    <option value="0">请选择上级客户</option>
								<?php foreach($top_level as $top_level_item):?>
									 <option value=<?= $top_level_item->id?>><?= $top_level_item->customer_name?></option>
								<?php endforeach;?>
							  </select> -->
						<input type="button" value="" class="g_title_sub">
					</div>
					<div class="g_select">
                       <?php
						$user_name = $this->session->userdata ( 'username' );
						$role = $this->session->userdata ( 'role' );
						?>
                       		<?php if($role == '经理' || $role == '商务助理'):?>
                    	<select id="check_info">
							<option value="0" <?php if($check_user_name == ''):?>
								selected='selected' <?php endif;?>>请选择所有者</option>
                    	<?php foreach ($all_users as $user):?>
                    	    	<?php if($user->user_name != '何俊斌'):?>
                    			<option value="<?= $user->id?>"
								<?php if($user->user_name == $check_user_name):?>
								selected='selected' <?php endif;?>><?= $user->user_name?></option>
                    		<?php endif;?>
                        <?php endforeach;?>
                        </select>
                        <?php endif;?>
                    </div>
					<div class="gj_earch">
						<select id="city">
							<option value="zero">请选择市区</option>
                            <?php foreach ($parent_customers as $parent_item):?>
                            	<option value="<?= $parent_item->id?>" <?php if($city_id == $parent_item->id):?> selected='selected' <?php endif;?>>
                            		<?= $parent_item->customer_name?>
                            	</option>
                            <?php endforeach;?>
                        </select> <select class="gj_earch_2" id="county">
							<option value="0">请选县区</option>
                        	<?php foreach ($county_customers as $item_customer):?>
                        		<option value=<?= $item_customer->id?> <?php if($county_id == $item_customer->id):?> selected='selected' <?php endif;?>>
                        		  <?= $item_customer->customer_name?>
                        		</option>
                        	<?php endforeach;?>
                        </select> <input type="button" value=""
							id="county_button" class="gj_earch_but">
					</div>
					<script type="text/javascript">
						$(function(){
							 $("#city").change( function() {
							 	var city = $("#city").val();
							 	if(city == 'zero'){
							 		$("#county").html('');
							 		$("#county").append('<option value="0">请选县市区</option>');
								 }else{
									 $.ajax({
											type: "POST",
											dataType: "text",
											url: "<?= base_url()?>index.php/customer/get_county",
											data: "parent_id="+city,
											success: function(data) {
												  $("#county").html('');
												  data=$.parseJSON(data);
												  var array='<option value="0">请选县区</option>';
												  $.each(data,function(index,nw){
												  	array+="<option value="+nw.id+">"+nw.customer_name+"</option>";
					                	 		});
												$("#county").append(array);
											}
										});
								}
							 })
						})
					</script>
					<div class="add_customer">
						<div class="add_customer_bg1"><?= anchor('customer/show_customer_add/',' ','class="various1"','id="find"') ?></div>
					</div>
				</div>
				<table id="ContentTable" class="data-box">
					<thead>
						<tr class="border-in">
							<th><div>ID</div></th>
							<th><div>客户名称</div></th>
							<th><div>所有者</div></th>
							<th><div>所属区域</div></th>
							<th><div>创建日期</div></th>
							<th><div>操作</div></th>
						</tr>
					</thead>

					<!-- 父级客户 -->

					<tbody id="tbody_g_tit">
					<?php $i=0;?>
					<?php foreach ($customer as $customer_item): ?>
					<tr class="data-box-row">
							<td><?= $customer_item->id ?></td>
							<td>
							   <div <?php if(($customer_item->cus_name_list != 'none')){?> class="cus_name_list" <?php }?>>
							   		<?php if(($customer_item->cus_name_list == 'none')){?> &nbsp;&nbsp; <?php }?>
							   		<?= $customer_item->customer_name ?>
							   </div>
							</td>
							<td><?= $customer_item->user_name ?></td>
							<td><?= $customer_item->address ?></td>
							<?php
								if ($customer_item->update_time == null || $customer_item->update_time == '' || $customer_item->update_time == '0000-00-00 00:00:00') {
									$updatetime = '';
								} else {
									$datatime = strtotime ( $customer_item->update_time );
									$updatetime = date ( "Y-m-d", $datatime );
								}
								if ($customer_item->create_time == null || $customer_item->create_time == '' || $customer_item->create_time == '0000-00-00 00:00:00') {
									$createtime = '';
								} else {
									$datatime = strtotime ( $customer_item->create_time );
									$createtime = date ( "Y-m-d", $datatime );
								}
							?>
							<td><?= $createtime ?></td>
							<?php $user_name = $this->session->userdata('username');?>
							<?php if ($customer_item->share == $user_name || $customer_item->share || $customer_item->user_id == $this->session->userdata('id') || $this->session->userdata('role') == '经理' || $this->session->userdata('role') == '商务助理'){ ?>
								<td><a
								href="<?= base_url()?>index.php/customer/find/<?= $customer_item->id ?>"
								class="various1 g_see" id="find" title="">查看</a>&nbsp;&nbsp;
								<a href="<?= base_url()?>index.php/customer/edit/<?= $customer_item->id ?>/<?= $offset?>"
								class="various1 g_edit" id="find" title="">编辑</a>&nbsp;&nbsp;

								<?php if(($customer_item->user_id == $this->session->userdata('id')) || ($this->session->userdata('role') == '经理')):?>
									<span class="g_dele" id="delete<?= $customer_item->id ?>">删除</span>
								<?php endif;?>

								<input type="hidden" id="customer_id<?= $customer_item->id ?>"
								value="<?= $customer_item->id ?>" /> <script
									type="text/javascript">
                                     $(function(){
                                    	 $("#delete<?= $customer_item->id ?>").click(function(){
                                  			if (window.confirm("您确定要删除吗？")) {
                                  				var id=$("#customer_id<?= $customer_item->id ?>").val();
                                  				location.href="<?= base_url()?>index.php/customer/delete/"+id+"";
                                  			} else {
                                  			}
                                  		})
                                     })
								</script></td>
							<?php }else{ ?>
							<td></td>
							<?php }?>
						</tr>
						<?php if($customer_item->counties):?>
							<?php foreach ($customer_item->counties as $counties_item): ?>
							<tr class="a<?= $i?>" style="display: none;">
								<td><?= $counties_item->id ?></td>
								<td>&nbsp;&nbsp;&nbsp;&nbsp;---<?= $counties_item->customer_name ?></td>
								<td><?= $counties_item->user_name ?></td>
								<td><?= $counties_item->address ?></td>

								<?php
									if ($customer_item->update_time == null || $customer_item->update_time == '' || $customer_item->update_time == '0000-00-00 00:00:00') {
										$updatetime = '';
									} else {
										$datatime = strtotime ( $customer_item->update_time );
										$updatetime = date ( "Y-m-d", $datatime );
									}
									if ($customer_item->create_time == null || $customer_item->create_time == '' || $customer_item->create_time == '0000-00-00 00:00:00') {
										$createtime = '';
									} else {
										$datatime = strtotime ( $customer_item->create_time );
										$createtime = date ( "Y-m-d", $datatime );
									}
								?>

								<td><?= $createtime ?></td>
								<td>
									<a href="<?= base_url()?>index.php/customer/find/<?= $counties_item->id ?>" class="various1 g_see" id="find" title="">查看</a>&nbsp;&nbsp;
									<a href="<?= base_url()?>index.php/customer/edit/<?= $counties_item->id ?>/<?= $offset?>" class="various1 g_edit" id="find" title="">编辑</a>&nbsp;&nbsp;
									<?php if(($counties_item->user_id == $this->session->userdata('id')) || ($this->session->userdata('role') == '经理')):?>
										<span class="g_dele" id="delete<?= $counties_item->id ?>">删除</span>
									<?php endif;?>
									<input type="hidden" id="customer_id<?= $counties_item->id ?>" value="<?= $counties_item->id ?>" />
									<script type="text/javascript">
	                                     $(function(){
	                                    	 $("#delete<?= $counties_item->id ?>").click(function(){
	                                  			if (window.confirm("您确定要删除吗？")) {
	                                  				var id=$("#customer_id<?= $counties_item->id ?>").val();
	                                  				location.href="<?= base_url()?>index.php/customer/delete/"+id+"";
	                                  			} else {
	                                  			}
	                                  		})
	                                     })
									</script>
							     </td>
							</tr>
							<?php endforeach;?>
							<?php $i++;?>
						<?php endif;?>
		          <?php endforeach; ?>
		        </tbody>
				</table>

				<div id="PageControl">
					<div class="page-control">
						<div class="border-in">
							<span class="perpage"> <span class="perpage-text">
							<?php if($pag_links || $check_cus_pag_links){?>
								<?echo ($offset) ? ($offset+1):1;?> - <?=$current_total?> 条（共<?=$total?>条）
							<?php }?>
							</span>
							</span>
							<p>
							    <?php

											if ($pag_links) {
												echo $pag_links;
											}
											?>
							</p>
						</div>
					</div>
				</div>
			</div>
			<!---------结尾------------->
			<?php include('footer.php')?>
		</div>
	</div>
	<input type="hidden" id="baseurl" value="<?=base_url()?>" />
	<input type="hidden" id="cus_error_info" value="<?= $error_info?>" />
	<script type="text/javascript">
		$(document).ready(function(){
			var $cnlobj = $('#tbody_g_tit div.cus_name_list');
			$cnlobj.click(function(){
				var i = $cnlobj.index(this);
				$(".a"+i).toggle();
				$cnlobj.eq(i).toggleClass('cur');
			});

			var cus_error_info = $('#cus_error_info').val();
			if(cus_error_info){
				alert(cus_error_info);
			}

			$("table").delegate('tr',"hover", function(){
				$(this).toggleClass("hover");
			});
			//$("table").delegate('tr',"mouseout", function(){
				//$(this).removeClass("hover");
			//});
		});
	</script>
</body>
</html>